/**
 * 
 */
package com.hfjyz.exam.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import com.hfjyz.exam.service.LoadUserService;

/**
 *
 */
public class LoadUserController extends SimpleFormController {
	private LoadUserService loadUserService;

	/**
	 * @return the LoadUserService
	 */
	public LoadUserService getLoadUserService() {
		return loadUserService;
	}

	/**
	 * @param LoadUserService
	 *            the LoadUserService to set
	 */
	public void setLoadUserService(LoadUserService loadUserService) {
		this.loadUserService = loadUserService;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax
	 * .servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse,
	 * java.lang.Object, org.springframework.validation.BindException)
	 */
	@Override
	protected ModelAndView onSubmit(HttpServletRequest request,
			HttpServletResponse response, Object command, BindException errors)
			throws Exception {

		MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
		MultipartFile multipartFile = multipartRequest
				.getFile("loadUserAddress");
		loadUserService.analyzeUserInfo(request, multipartFile, errors);
		if (errors.hasErrors()) {
			return new ModelAndView(getFormView(), errors.getModel());
		}
		return new ModelAndView(getSuccessView(), errors.getModel());
	}
}
